<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    <script>
        //自定义对象
        var user = {
            name: "Tom",
            age: 10,
            gender: "男",
            eat(){
                alter("用膳")
            }
        }

        alter(user.name);
        user.eat();
        var jsonUser = '{"name":"tom","age":"18","gender":"男"}';//JSON字符串
        alter(jsonUser.name);//会显示没有定义
        //json字符串--js对象
        var obj = JSON.parse (jsonstr) ;
        alert (obj . name) ;
        //js对象--json字符串
        alert (JSON. stringify (obj));


    </script>

</body>
</html>